#include "qcomp.h"

QComp::QComp(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
}

QComp::~QComp()
{

}
void QComp::update(AudioManager::Manager * aManager,int track_ID){
	float *value=0;
	char* title=0;
	aManager->getTrackDSP(FMOD_DSP_TYPE_COMPRESSOR,track_ID)->getParameter(FMOD_DSP_COMPRESSOR_ATTACK,value,title,10);
	ui.atckSlider->setValue(*value);
	aManager->getTrackDSP(FMOD_DSP_TYPE_COMPRESSOR,track_ID)->getParameter(FMOD_DSP_COMPRESSOR_RELEASE,value,title,10);
	ui.releaseSlider->setValue(*value);
	aManager->getTrackDSP(FMOD_DSP_TYPE_COMPRESSOR,track_ID)->getParameter(FMOD_DSP_COMPRESSOR_GAINMAKEUP,value,title,10);
	ui.gainSlider->setValue(*value);
	aManager->getTrackDSP(FMOD_DSP_TYPE_COMPRESSOR,track_ID)->getParameter(FMOD_DSP_COMPRESSOR_THRESHOLD,value,title,10);
	ui.thresholdSlider->setValue(*value);
	cout<<title<<"  "<<value;
}

void QComp::enable(){
	bool *bypass=false;
	FMOD_RESULT result=fx->getBypass(bypass);
	if (result != FMOD_OK)
    {
        printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
		std::system("PAUSE");
        exit(-1);
    }
	else{
		fx->setBypass(!bypass);	
	}
	cout<<bypass;
}

void QComp::setAtk(int value){
	if(fx!=NULL){
		fx->setParameter(FMOD_DSP_COMPRESSOR_ATTACK, value);
	}
}
void QComp::setRelease(int value){
	if(fx!=NULL){
		fx->setParameter(FMOD_DSP_COMPRESSOR_RELEASE, value);
	}
}
void QComp::setGain(int value){
	if(fx!=NULL){
		fx->setParameter(FMOD_DSP_COMPRESSOR_GAINMAKEUP, value);
	}
}
void QComp::setTreshold(int value){

	if(fx!=NULL){
		fx->setParameter(FMOD_DSP_COMPRESSOR_THRESHOLD, value);
	}
}
void QComp::setCompFX(FMOD::DSP * comp){
	fx=comp;
}
